var analysisForm = new Form();
var analusisAjax = new Ajax();
var analysisColumn = new Column();

$(function() {
	$("#main").height("95%");
	initScripts();
	initForm();
	initHeight();
	initDate();
});

function initScripts() {
	loadScript(appPath
			+ "/project-yddemo/indicatorAnalysis/locale/IndicatorAnalysisLocale_"
			+ appLocale + ".js"); // 1.加载国际化js*
	loadScript(appPath
			+ "/project-yddemo/indicatorAnalysis/properties/IndicatorAnalysisProperties.js"); // 1.加载国际化js*
}

function initForm() {
	analysisForm.initTableConditions({
		divId : "selectDiv",
		conditions : IndicatorAnalysysProperties.getConditionData(),
		button : { // 4.操作按钮*
			width : "120", // 占用宽度*
			align : "left", // left,center,right,百分比*
			label : indicatorRoleLocale.text.search, // 文本*
			action : "yddemo:analysis:view",
			clickFun : function() { // 按钮事件*
				initColumn();
				initHeight();
			}
		}
	});
}
function initHeight() {
	var mainHeight = $("#main").height();
	var selectHeight = $("#selectDiv").height();
	$("#chartDiv").height(mainHeight - selectHeight);
}
/** 初始化日期控件 * */
function initDate() {
	$("[key='beginTime']").jeDate({
		isinitVal : true,
		initAddVal : {
			YYYY : 0,
			MM : 0,
			DD : 0
		},
		ishmsVal : false,
		format : "YYYY-MM-DD",
		zIndex : 3000,
		language : getJeDateLanguage()
	});
}
function initColumn() {
	var conditions = analysisForm.getQueryConditions();
	if(conditions==null){
		conditions="发电量";
	}
	if (conditions.beginTime != undefined && conditions.beginTime != "") {
		conditions.beginTime = TimeObjectUtil
				.dateToLongMsTime(conditions.beginTime);
	}

	 conditions.indicatorName=getRequest().indicatorName;
	var datas = analusisAjax.sendAjax({
		url : requestPath + "/yddemo/indicatorAnalysiss/day",
		async : false,
		type : "GET",
		data : conditions
	});
	analysisColumn.initColumn("chartDiv", {
		title : conditions.indicatorName,
		series : datas
	}, false);
}

function getRequest() {  
    var url = window.location.search; //获取url中"?"符后的字串   
    var theRequest = new Object();   
    if (url.indexOf("?") != -1) {   
       var str = url.substr(1);   
       strs = str.split("&");   
       for(var i = 0; i < strs.length; i ++) {   
           //就是这句的问题
          theRequest[strs[i].split("=")[0]]=decodeURI(strs[i].split("=")[1]); 
          //之前用了unescape()
          //才会出现乱码  
       }   
    }   
    return theRequest;   
 }